package com.sxt.bus.service.imp;

import com.sxt.bus.domain.*;
import com.sxt.bus.mapper.*;
import com.sxt.bus.service.SalesbackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxt.sys.common.WebUtils;
import com.sxt.sys.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2019-12-26
 */
@Service
public class SalesbackServiceImpl extends ServiceImpl<SalesbackMapper, Salesback> implements SalesbackService {

    @Resource
    private SalesMapper salesMapper;
    @Resource
    private GoodsMapper goodsMapper;
    @Resource
    private ProviderMapper providerMapper;


    @Override
    public void addSalesback(Integer id, Integer number, String remark) {
        //根据进货单id查询进货单信息
        Sales sales = this.salesMapper.selectById(id);
       /* sales.setNumber(sales.getNumber()-number);
        this.salesMapper.updateById(sales);*/
        //根据商品id 查询商品信息
        Goods goods = this.goodsMapper.selectById(sales.getGoodsid());
        goods.setNumber(goods.getNumber()+number);

        //添加退货单信息
        Salesback salesback = new Salesback();
        salesback.setGoodsid(sales.getGoodsid());
        salesback.setNumber(number);
        salesback.setPatientid(sales.getPatientid());
        User user = (User) WebUtils.getSession().getAttribute("user");
        salesback.setOperateperson(user.getName());
        salesback.setSalebackprice(sales.getSumprice());
        salesback.setSalesbacktime(new Date());
        salesback.setPaytype(sales.getPaytype());
        salesback.setRemark(remark);
        this.getBaseMapper().insert(salesback);


    }

}
